﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="../index/meta.jsp" %>
    <title></title>
    <meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form method="post" class="form form-horizontal" id="form">
	    <input type="hidden" name="id" value="${role.id}" />
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${role.name}" placeholder="请输入角色名称:" id="name" name="name" />
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色编码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${role.code}" placeholder="请输入角色编码:" id="code" name="code" />
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea class="textarea" placeholder="请描述角色描述信息:" id="description" name="description" >${role.description}</textarea>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="update"><i class="icon-ok"></i>更新</button>
			</div>
		</div>
	</form>
</article>

<%@ include file="../index/footer.jsp" %>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/plugins/jquery.validation/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/plugins/jquery.validation/validate-methods.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/plugins/jquery.validation/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	
	$("#form").validate({
		rules:{
			name:{
				required:true,
			},
			description:{
				required:true,
			}
		},
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		submitHandler:function(form){
			var pageContext = "${pageContext.request.contextPath}";
			$(form).ajaxSubmit({
				url:pageContext+"/roleServlet?method=update",    //请求的url地址
			    dataType:"json",   //返回格式为json
			    async:true,//请求是否异步，默认为异步，这也是ajax重要特性
			    type:"POST",   //请求方式
			    beforeSend:function(){
			        //请求前的处理
			    },
			    success:function(req){
			        //请求成功时处理
			        if(req.success) {
			        	layer.msg(req.msg, {
			        		  icon: 6,
			        		  offset: '100px',
			        		  time: 1500 //2秒关闭（如果不配置，默认是3秒）
		        		}, function(){
		        			parent.location.href=pageContext+"/roleServlet?method=list";
		        		});
			        } else {
			        	layer.msg(req.msg, {
			        		  icon: 5,
			        		  offset: '100px',
			        		  time: 1500 //2秒关闭（如果不配置，默认是3秒）
		        		}, function() {
		        			var index = parent.layer.getFrameIndex(window.name);
				   			parent.layer.close(index);
		        		}); 
			        }
			    },
			    error:function(xhr){
			    	layer.msg('抱歉！出错！联系 313355817@qq.com', {
		        		  icon: 5,
		        		  offset: '100px',
		        		  time: 2000 //2秒关闭（如果不配置，默认是3秒）
	        		}, function() {
	        			var index = parent.layer.getFrameIndex(window.name);
			   			parent.layer.close(index);
	        		}); 
			    }
			});
		}
	});
});
</script>
</body>
</html>